import api from "@/api/http";
import { ApiResponse, ListResponse } from "@/api/types/ApiResponse";
import { SearchKeyQueryParam } from "@/api/types/QueryParam";


export interface SysTbDictGroupResponse {
  id: string,
  groupName: string,
  groupCode: string,
  allowEdit: number,
  allowDel: number,
  createTime: string,
  updateTime: string,
  createUserAccount: string,
  updateUserAccount: string,
  parentGroupCode: string,
  fullGroupCode: string,
  fullGroupName: string,
  orderIndex: number,
}

export interface SelectSysTbDictGroupPageListQueryParam extends SearchKeyQueryParam {

}

/**
 * 分页查询列表
 * @param query
 */
export const selectPageList = (query: SelectSysTbDictGroupPageListQueryParam): Promise<ListResponse<SysTbDictGroupResponse>> => {
  return api.doGet("/SysApp/SysTbDictGroup/selectPageList", query);
};
export const selectTreeList = (query: SelectSysTbDictGroupPageListQueryParam): Promise<ListResponse<SysTbDictGroupResponse>> => {
  return api.doGet("/SysApp/SysTbDictGroup/selectTreeList", query);
};
/**
 * 根据ID查询
 * @param id
 */
export const selectById = (id: string | number): Promise<ApiResponse<SysTbDictGroupResponse>> => {
  return api.doGet("/SysApp/SysTbDictGroup/selectById", { id: id });
};
/**
 * 更新排序
 * @param data
 */
export const doUpdateOrderIndex = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbDictGroup/updateOrderIndex", data);
};

/**
 * 新增
 * @param data
 */
export const doSaveEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbDictGroup/save", data);
};
/**
 * 实体
 * @param data
 */
export const doUpdateEntity = (data: any): Promise<ApiResponse<boolean>> => {
  return api.doPost("/SysApp/SysTbDictGroup/update", data);
};
/**
 * 逻辑删除
 * @param id|ids
 */
export const doLogicDeleteEntity = (ids: Array<string | number> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/SysTbDictGroup/logicDelete", data);
};
/**
 * 物理删除
 * @param id|ids
 */
export const doDeleteEntity = (ids: Array<string> | number | string): Promise<ApiResponse<boolean>> => {
  let data: any = null;
  if (Array.isArray(ids)) {
    data = ids;
  } else {
    data = [ids];
  }
  return api.doPost("/SysApp/SysTbDictGroup/delete", data);
};

export default {
  selectTreeList,
  doUpdateOrderIndex,
  selectPageList,
  selectById,
  doDeleteEntity,
  doLogicDeleteEntity,
  doUpdateEntity,
  doSaveEntity
};
